package Reaction::InterfaceModel::Action::User::ResetPassword;

use Reaction::Class;
use Digest::MD5;

use aliased
  'Reaction::InterfaceModel::Action::User::Role::ConfirmationCodeSupport';
use aliased 'Reaction::InterfaceModel::Action::User::SetPassword';

class ResetPassword is SetPassword, which {

  does ConfirmationCodeSupport;

  has confirmation_code => (
   isa => 'NonEmptySimpleStr', is => 'rw',
   set_or_lazy_fail('confirmation_code'),
   predicate => 'has_confirmation_code',
  );
  
  around error_for_attribute => sub {
    my $super = shift;
    my ($self, $attr) = @_;
    if ($attr->name eq 'confirmation_code') {
      return "Confirmation code incorrect"
        unless $self->verify_confirmation_code;
    }
    #return $super->(@_); #commented out because the original didn't super()
  };
  
  implements verify_confirmation_code => as {
    my $self = shift;
    return $self->has_confirmation_code
        && ($self->confirmation_code eq $self->generate_confirmation_code);
  };

};

1;
